#include <REGX52.H>
#include "Delay.h"
#include "LCD1602.h"
#include "Timer0.h"

unsigned char Sec,Min,Hour;

void main()
{
	LCD_Init();
	Timer0Init();
	
	LCD_ShowString(1,1,"Clock:");
	LCD_ShowString(2,1,"  :  :");//LCD显示字符串函数
      while(1)
{
	     LCD_ShowNum(2,1,Hour,2);  //LCD显示数字函数
       LCD_ShowNum(2,4,Min,2);    
       LCD_ShowNum(2,7,Sec,2);    	
}
}

void Timer0_Routine() interrupt 1
{
	static unsigned int T0Count;
  TL0 = 0x18;		//设置定时初值
	TH0 = 0xFC;	
	T0Count++;    //当T0count满1000时，定时器正好为1s
	if(T0Count>=1000)
	{
		T0Count=0;  //重新从0开始
		Sec++;      //秒加1
		if(Sec>=60)
		{
			Sec=0;    //当秒数大于60，清零
			Min++;    //分钟数清零
			if(Min>=60)
			{
				Min=0;  //分钟数大于60时，清零
				Hour++; //小时加加
				if(Hour>=24)
				{
					Hour=0; 
					
				}
			}
		}
	}
}	